#include<stdio.h>
#include<stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>


/*void pri()
{
    printf("hello world");
    _exit(0);
}
*/

int main()
{

    pid_t pid = fork();
    
    if(pid==-1)
    {
        perror("fork");
        exit(1);
    }
    
    if(pid ==0)
    {
        sleep(20);
        exit(10);
    }else
    {
        int status;
        int ret = wait(&status);
        if(ret>0&&(status&0x7f)==0)
        {
            printf("child exit code:%d\n",(status>>8)&0xff);
        }else if(ret >0)
        {
            printf("sig code: %d \n",status&0x7f);
        }
    }
    
    
   // pid_t id = fork();
    //if(id<0)
   // {
        //perror("fork");
        //return 1;
    //}else if(id==0)
    //{
        //printf("child[%d] id begin Z....\n",getpid());
        //sleep(5);
        //exit(EXIT_SUCCESS);
    //}else
    //{
        //printf("parent[%d] id begin ....\n",getpid());
        //sleep(30);
        
    //}
    //return 0;
     //extern char **environ;
     //int i = 0;
    // for(; environ[i]; i++){
        // printf("%s\n", environ[i]);
    // }
    
    //pid_t pid;
    //printf("Before: pid is %d\n", getpid());
    //if ( (pid=fork()) == -1 )perror("fork()"),exit(1);
    //printf("After:pid is %d, fork return %d\n", getpid(), pid);
    //sleep(1);
    //pri();
    //return 0;
}
